Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FIX] prevent a warning message #644

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from

Conversation

benwillig
Copy link

Use args[0] instead of name to get the exception message as the name attribute is deprecated

@OCA-git-bot
Copy link
Contributor

Hi @guewen,
some modules you are maintaining are being modified, check this out!

@OCA-git-bot
Copy link
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

Copy link
Contributor

@simahawk simahawk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, could you pls rewrite the commit msg to something like

[fix] queue_job: fix exception msg handling

.... long explanation goes here...

@@ -160,7 +160,7 @@ def _get_failure_values(self, job, traceback_txt, orig_exception):
exception_name = orig_exception.__class__.__name__
if hasattr(orig_exception, "__module__"):
exception_name = orig_exception.__module__ + "." + exception_name
exc_message = getattr(orig_exception, "name", str(orig_exception))
exc_message = getattr(orig_exception, "args[0]", str(orig_exception))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure the this instance has an attribute called "args[0]"? This seems broken to me 🤔
args will be always there and very likely you'll have a first arg.

I guess you want to have something like orig_exception.args[0] if orig_exception.args else str(orig_exception).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per 8.3 Handling Exceptions 1,

The except clause may specify a variable after the exception name. The variable is bound to the exception instance which typically has an args attribute that stores the arguments. For convenience, builtin exception types define str() to print all the arguments without explicitly accessing .args.

"Typically" suggests that args will be absent some of the time.

  1. At the risk of having a slightly uglier error message, why not just use str(orig_exception) instead of trying to preserve formatting?
  2. If the exception handling behavior is changing, it should be covered by unit tests.

Footnotes

  1. https://docs.python.org/3/tutorial/errors.html#handling-exceptions

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed the syntax looks weird so your proposal would be better. However, @amh-mw made a point so I think it would be better to simply use str(orig_exception).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I can give you a little background as I'm the author of this piece of code 😉

The aim was to clearly rip out of the msg the exception class. That's why we have exc_name and exc_message. Exceptions are already messy for end users and this is an attempt to have a better msg.
Not to mention that this proposal will cause duplication of info because the exc name will be repeated.
Hence, calling str was just a safe fallback to make sure you had a msg.

An alternative is to call str and drop surrounding chars like exc name, parentesis, etc but I find this more complex than the little check here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the commit

'name' attributes for odoo's exception has been deprecated and produces a warning message. This commit fixes the behavior
@benwillig benwillig force-pushed the 16.0-fix_exception_name_to_args0-bwi branch from 43d0e46 to 8479b13 Compare May 30, 2024 09:29
Copy link

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Sep 29, 2024
Azerty-Dick pushed a commit to Azerty-BV/oca_queue that referenced this pull request Oct 4, 2024
It doesn't make sense and even more, it crashed.

Fixes OCA#644
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale PR/Issue without recent activity, it'll be soon closed automatically.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants